<template>
	<div class="view">
		<city-select :obtainCitys="obtainCitys" :hotCity='hotCity' :activeCity="activeCity" :formatName="formatName"
			:isSearch='false' @cityClick="cityClick">
		</city-select>
	</div>
</template>

<script>
	import {
		getregion,
		getHotCityList
	} from "@/apis/request.js";
	import citySelect from "@/components/city-select/city-select.vue"
	export default {
		components: {
			citySelect
		},
		data() {
			return {
				formatName: 'title',
				//当前城市
				activeCity: {},
				//热门城市
				hotCity: [],
				//显示的城市数据
				obtainCitys: []
			};
		},
		onLoad() {
			this.init();
		},
		methods: {
			async init() {
				const allArr = [];
				const hotArr = [];
				const allCityList = await getregion({
					regionGrade: 2
				});
				const hotCityList = await getHotCityList();
				allCityList.filter(item => {
					allArr.push({
						id: item.id,
						title: item.regionName
					});
				});
				hotCityList.filter(item => {
					hotArr.push({
						id: item.id,
						title: item.regionName
					});
				});
				this.obtainCitys = allArr;
				this.hotCity = hotArr;
				//当前城市
				this.activeCity = uni.getStorageSync('city')
			},
			cityClick(data) {
				uni.setStorageSync('city', data)
				const eventChannel = this.getOpenerEventChannel()
				eventChannel.emit('changeCity', data)
				uni.navigateBack({
					delta: 1,
				})
			}
		},
	};
</script>

<style lang="scss" scoped>

</style>